<%-- 
    Document   : zk_major
    Created on : 2016-8-17, 11:55:50
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <%@include file="../../link.jsp" %>
        <title>专业组管理</title>
    </head>
    <style>
        tr>td{
            padding: 4px 4px 4px 4px;
            /*padding-bottom: 4px;*/
        }
        th{
            padding:4px 4px 4px 4px;
            font:bold;
            text-align:center;
        }
        .error{font-size: 1px; color: red}
    </style>
    <body style="font-family: 微软雅黑;margin-top: 10px;" ng-app="zkMajor" ng-controller="mainTab">
          <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading"><span style="float: left">专业组列表</span>
                    <div>
                        <input  ng-model="searchContent" placeholder="试剂编号/供应商" style="width:320px; float: left;margin-left: 20px"  class="form-control input-sm" />
                        <button ng-click="getZkMajors()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>

                        <button ng-click="OpenSaveModal()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;添加</button></div>

                    <div style="clear: both"></div>
                </div>

                <table class="table table-striped table-bordered  table-hover ">
                    <thead>
                       <tr>
                                <th class="table-id">序号</th>
                                <th class="table-id">专业组名</th>
                                
                                 <th class="table-set">操作</th>
                            </tr>
                    </thead>
                    <tbody>
                            <tr  ng-repeat="major in majors" >
                                <td >{{$index}}</td>
                                <td>{{major.MAJORNAME}}</td>
                                   
                                <td>
                                    <button ng-click="OpenUpdateModal(major)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>修改</button>
                                    <button ng-click="deleteZkMajor(major)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>删除</button>
                                </td>
                            </tr>
                    </tbody>
                </table>  
                  
                <footer class="panel-heading">
                    <div class="row">
                        <div style="text-align: center" >                
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>
                    </div>
                </footer>

            </div>

        </div>

        
            <div class="modal fade mode-x" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">{{title}}专业组</h4>
                    </div>
                    <div class="modal-body">
                            <form  name="formMajor" id="profile">
                            <table style="width: 100%">                             
                                <tr>
                          
                                    <td>专业组名称：<input type="text" name="majorName" ng-model="tmpMajor.MAJORNAME" style="width: 100px" ng-minlength=1 ng-maxlength=20 required><label style="color:red;">&lowast;</label>
                         <div class="error" ng-show="formMajor.majorName.$dirty && formMajor.majorName.$invalid">
                         <small class="error" ng-show="formMajor.majorName.$error.required">专业组名不能为空。</small>
                         <small class="error" ng-show="formMajor.majorName.$error.minlength">专业组名长度不能小于1</small>
                         <small class="error" ng-show="formMajor.majorName.$error.maxlength">专业组名长度不能大于20</small> 
                         </div>
                      </td>
                     <td>
                         
                     </td>
                                </tr>
                             
                            </table>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                        <button  ng-click="saveMa()"   ng-disabled="formMajor.$invalid" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                    </div>
                </div> 
            </div> 
        </div>
        
        
    </body>
    <script>
         angular.module("zkMajor", ['baseModule', 'ui.bootstrap'])
            .controller("mainTab", function ($scope,base) {
 
                 $scope.tmpMajor={PK:""};
                 $scope.searchContent="";
                   
                $scope.data = {currentPage: 1};
                $scope.setPage = function (pageNo) {
                    $scope.data.currentPage = pageNo;
                };
                $scope.pageChanged = function () {
                    $scope.getZkMajors();
                };
                $scope.data.maxSize = 2;
                $scope.data.bigTotalItems = 20;
                $scope.data.bigCurrentPage = 1;
                $scope.data.pageSize = 10;

                $scope.getZkMajors=function(){//显示
                base.post("zkmajor/getZkMajors",{pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage,searchContent:$scope.searchContent}).get(function(data){ //参数 分页参数
//                    console.log(data);
                    if(data){
                       $scope.majors=data.list;
                       $scope.data.bigTotalItems = data.totalRow;
//                       $scope.$apply();
                    }
                })
            }
            $scope.getZkMajors();
               $scope.deleteZkMajor=function(tmp){
                
                  var gnl=confirm("你真的确定要删除吗?"); //友好提示
                if (gnl==true){ 
                base.post("zkmajor/deleteZkMajor",{PK:tmp.PK}).get(function(data){
                    if(data=='true'){
                        alert("删除成功",1000);
                        $scope.getZkMajors();
                        $scope.$apply();
                    }
                })
            }else{
                return;
            }
            }
                
                 $scope.OpenSaveModal = function () {
                     $scope.title="新增";
                     $scope.tmpMajor={PK:""};
                    $(".mode-x").modal('show');
                }
                $scope.OpenUpdateModal=function(tmp){
                      $scope.title="修改";
                     $scope.tmpMajor=tmp;
                    $(".mode-x").modal('show');   
                }
               $scope.CloseModel=function(){//关闭窗口的同时清空窗口数据
                   $scope.tmpMajor={PK:""};
                   $scope.getZkMajors();
               }
               
               $scope.saveMa=function(){//必须要验证 显示序号 和扩展类型为数值
                
                 base.post("zkmajor/getZkMajorsRep",$scope.tmpMajor).get(function(data){
                     if(data=='true'){
                         alert("专业组在数据库中已存在",1000);
                         return;
                     }
            
                 if($scope.tmpMajor.PK!=""){//修改
//                    alert(2);
                     base.post("zkmajor/updateZkMajor",$scope.tmpMajor).get(function(data){
                    if(data=='true'){
                         alert("修改成功！");
                       $scope.getZkMajors();
                       
                    }
                })  
                 }else{//保存 
//                      alert(3);
                    base.post("zkmajor/saveZkMajor",$scope.tmpMajor).get(function(data){
                    if(data=='true'){
                        alert("新增成功！");
                       $scope.getZkMajors();
                        
                    }
                })
                 }
                 
                  $(".mode-x").modal('hide');
                 $scope.CloseModel();
                 
                
                 })  
               }
            })
    </script>
</html>